$(function() {
    $('input[name=typeid]').click(function() {
        var value = $(this).val();
        if (2 === parseInt(value)) {
            $('.typeid2').show();
        } else {
            $('.typeid2').hide();
        }
    });
});

// 判断输入框是否为空
function submitForm(submitFormID) {
    if ($('#url').val() == '') {
        showErrorMsg('请填写网址URL');
        $('#url').focus();
        return false;
    } 
    else if ($('#title').val() == '') {
        showErrorMsg('请填写网站名称');
        $('#title').focus();
        return false;
    }
    else if ($('input[name=typeid]:checked').val() == 2) {
        if ($('#is_remote').is(':checked')) {
            if ($('#logo_remote').val() == '') {
                showErrorMsg('请填写远程图片路径');
                $('#logo_remote').focus();
                return false;
            }
        } else {
            if ($('#logo_local').val() == '') {
                showErrorMsg('请上传网站Logo图片');
                $('#logo_local').focus();
                return false;
            }
        }
    }
    layer_loading('正在处理');
    $.ajax({
        type: 'post',
        url : submitFormUrl,
        data: $(submitFormID).serialize(),
        dataType: 'json',
        success: function(res) {
            layer.closeAll();
            if (1 === parseInt(res.code)) {
                var _parent = parent;
                _parent.layer.closeAll();
                _parent.showSuccessMsg(res.msg, 1000, function() {
                    _parent.window.location.reload();
                });
            } else {
                showErrorAlert(res.msg);
            }
        },
        error: function(e) {
            layer.closeAll();
            showErrorAlert(e.responseText);
        }
    });
}

function img_call_back(fileurl_tmp) {
    $("#logo_local").val(fileurl_tmp);
    $("#img_a").attr('href', fileurl_tmp);
    $("#img_i").attr('onmouseover', "layer_tips=layer.tips('<img src="+fileurl_tmp+" class=\\'layer_tips_img\\'>',this,{tips: [1, '#fff']});");
}